<template>
    <view class="container" v-if="datas.SkuList && datas.SkuList[0]">
        <view class="list" v-for="(item, index) in datas.SkuList[0].MenberList" :key="index">
            <view class="left">{{ item.GradeName }}</view>
            <view>
                <view class="flex-start"> <input type="number" v-model="item.Price" /><view>元</view> </view>
            </view>
        </view>
        <view class="footer">
            <view class="btn btn-success-hollow" @click="submit">保存</view>
        </view>
    </view>
</template>

<script>
import { mapMutations } from "vuex"
import { GetMemberProductInfo, SaveMemberProductInfo } from "@/pages_supplier/service/api/product.js"
export default {
    components: {},
    data() {
        return {
            datas: {},
            id: "",
            ProductUnit: {},
            ProductSkuList: [],
            costPrice: 0,
        }
    },
    onLoad(e) {
        this.id = e.id
    },
    mounted() {
        this.getinfo()
    },
    onShow() {},
    methods: {
        ...mapMutations(["UP_VIP_VIEW"]),
        getinfo() {
            let path = "?productId=" + this.id
            GetMemberProductInfo(path).then((res) => {
                if (res.State == 1) {
                    this.datas = res.Data
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        submit() {
            let verify = true
            this.datas.SkuList[0].MenberList.forEach((e, i) => {
                if (e.Price == "") {
                    this.easyToast("价格不能为空")
                    return (verify = false)
                }
            })
            if (!verify) {
                return
            }
            let parm = {}
            parm.ProductSkuMemberPriceList = []
            this.datas.SkuList.forEach((e, i) => {
                e.MenberList.forEach((sub, j) => {
                    let obj = {}
                    obj.GradeId = sub.ID
                    obj.ProductID = this.id
                    obj.SkuId = e.ID
                    obj.UnitId = e.UnitId
                    obj.MemberSalePrice = this.datas.SkuList[0].MenberList[j].Price
                    parm.ProductSkuMemberPriceList.push(obj)
                })
            })
            console.log(parm)
            SaveMemberProductInfo(parm).then((res) => {
                if (res.State == 1) {
                    this.easyToast("保存成功")
                    this.UP_VIP_VIEW(new Date().getTime())
                    setTimeout((e) => {
                        this.easyGoBack()
                    }, 1000)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss">
.container {
    padding: 24rpx 0 130rpx 0;
}
.list {
    display: flex;
    justify-content: space-between;
    background: #ffffff;
    padding: 16rpx 32rpx;
    font-size: 32rpx;
    margin-bottom: 24rpx;
    .left {
        padding-top: 32rpx;
    }
    input {
        width: 226rpx;
        height: 72rpx;
        background: #f4f5f6;
        border-radius: 36rpx;
        font-size: 32rpx;
        font-weight: bold;
        color: $app-color-main;
        margin-right: 18rpx;
        text-align: center;
    }
    .flex-start {
        padding: 20rpx 0;
        font-size: 30rpx;
    }
}
.btn {
    margin: 16rpx 30rpx 0 30rpx;
}
</style>
